﻿@model EOS.DataModel.Condition

@{
    ViewBag.Title = "Create";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Create</title>

    <script src="../../Content/jquery-easyui-1.5.2/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#CondString").attr("readonly", true)

            $("#condtion").change(function () {
                var str = $("#condtion").find("option:selected").text();
                if (str == "自定义") {
                    $("#propertyNames").attr("disabled", true)
                    $("#CondValue").attr("disabled", true)
                    $("#CondString").attr("readonly", false)
                    $("#btnCreate").attr("disabled", true)
                }
                else {
                    $("#propertyNames").attr("disabled", false)
                    $("#CondValue").attr("disabled", false)
                    $("#CondString").attr("readonly", true)
                    $("#btnCreate").attr("disabled", false)
                }
            })
        })

        function getExpression() {
            var strR = $("#Relation").find("option:selected").text();
            var str1 = $("#propertyNames").find("option:selected").text();
            var str2 = $("#condtion").find("option:selected").text();
            var str3 = $("#CondValue").val();
            var str = " " + str1 + str2 + str3 + " ";

            var strC = $("#CondString").val();
            if (strC.trim() == "") {
                $("#CondString").val(str);
            }
            else {
                $("#CondString").val(strC + strR + str);
            }
        }

        function clearExpression() {
            $("#CondString").val("");
        }
    </script>
</head>
<body>
    @using (Html.BeginForm())
    {
        @Html.AntiForgeryToken()

        <div class="form-horizontal">
            <h4>条件编辑</h4>
            <hr />
            @Html.ValidationSummary(true, "", new { @class = "text-danger" })
            <div class="form-group">
                @Html.Label("关联方式", htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.DropDownList("Relation", new SelectList(ViewBag.condtionRelation, "Value", "Text"), new { @class = "dropdown-toggle form-control" })
                </div>
            </div>

            <div class="form-group">
                @Html.Label("字段名", htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.DropDownList("propertyNames", ViewBag.propertyNames as IEnumerable<SelectListItem>, new { @class = "dropdown-toggle form-control" })
                </div>
            </div>

            <div class="form-group">
                @Html.Label("关系运算符", htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.DropDownList("condtion", new SelectList(ViewBag.condtion, "Value", "Text"), new { @class = "dropdown-toggle form-control" })
                </div>
            </div>

            <div class="form-group">
                @Html.Label("值", htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.TextBox("CondValue", "", new { @class = "form-control" })
                    <div class="btn-group">
                        <a href="#" id="btnCreate" class="btn btn-default" onclick="getExpression()">生成表达式</a>
                        <a href="#" id="btnClear" class="btn btn-default" onclick="clearExpression()">清空表达式</a>
                    </div>
                    @Html.ValidationMessageFor(model => model.CondString, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.Label("表达式", htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.TextAreaFor(model => model.CondString, htmlAttributes: new { @class = "form-control", @rows = "5" })
                    @Html.ValidationMessageFor(model => model.CondString, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                <div class="col-md-10">
                    @Html.HiddenFor(model => model.ID)
                    @Html.HiddenFor(model => model.R_LeaveStep_PageInfoID)
                </div>
            </div>

            <div class="form-group">
                <div class="col-md-offset-2 col-md-10">
                    <input type="submit" value="保存" class="btn btn-default" />
                </div>
            </div>
        </div>
    }

    <div>
        @*Html.ActionLink("返回绑定页面编辑", "LinkPage", "LeaveSteps", new { id = @ViewBag.R_LeaveStep_PageInfoID }, new { @class = "btn-link" })*@
    </div>
</body>
</html>